package com.lize;

import java.util.ArrayList;
import java.util.Comparator;

public class test {

    public static void main(String[] args) {
        ArrayList <Employee>arrayList = new ArrayList();
arrayList.add(new Employee("李泽",12,new Mydate(2012,7,1)));
arrayList.add(new Employee("韩顺平",35,new Mydate(1999,2,19)));
arrayList.add(new Employee("小布",23,new Mydate(2004,6,6)));
arrayList.sort(new Comparator<Employee>() {
    @Override
    public int compare(Employee o1, Employee o2) {
        if(o1.getName().length()!=o2.getName().length()){

            return o2.getName().length()-o1.getName().length();
        }
        else
        {

            Mydate d1 = o1.getBirthday();
            Mydate d2 = o2.getBirthday();
            // 比较年
            int yearCompare = Integer.compare(d1.getYear(), d2.getYear());
            if (yearCompare != 0) return yearCompare;
            // 比较月
            int monthCompare = Integer.compare(d1.getMot(), d2.getMot());
            if (monthCompare != 0) return monthCompare;
            // 比较日
            return Integer.compare(d1.getDay(), d2.getDay());
        }



    }
});

        System.out.println(arrayList);
    }
}
class Employee{
    private String name;
   private int age;
    private Mydate birthday;

    public Employee(String name, int age, Mydate birthday) {
        this.name = name;
        this.age = age;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Mydate getBirthday() {
        return birthday;
    }

    public void setBirthday(Mydate birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", birthday=" + birthday +
                '}';
    }
}
class Mydate{

    private  int year;
    private int mot;
    private  int day;

    public Mydate(int year, int mot, int day) {
        this.year = year;
        this.mot = mot;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMot() {
        return mot;
    }

    public void setMot(int mot) {
        this.mot = mot;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "Mydate{" +
                "year=" + year +
                ", mot=" + mot +
                ", day=" + day +
                '}';
    }
}